package com.example.service.student;

import com.example.entity.Account;
import com.example.entity.Student;
import com.example.exception.CustomException;
import com.example.mapper.StudentMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 学生登录
 */

@Service
public class StudentLoginService {
    @Resource
    private StudentMapper studentMapper;

    public Student login(Account account) {
        String username = account.getUsername();
        Student student = studentMapper.selectByUsername(username);
        if (student == null) {
            throw new CustomException("500", "学生不存在!");
        }
        String password = account.getPassword();
        if(!student.getPassword().equals(password)) {
            throw new CustomException("500", "学号或密码错误!");
        }
        return student;
    }
}
